package com.ty.paypal.service.plan;

import java.io.IOException;

import com.paypal.http.HttpResponse;
import com.paypal.http.exceptions.HttpException;
import com.ty.paypal.core.Product;
import com.ty.paypal.core.request.ProductCreateRequest;
import com.ty.paypal.core.request.body.ProductRequest;
import com.ty.paypal.service.PayPalClient;

 /**
  * 创建一个计划产品
  * @author ty
  *
  */
public class CreateProduct extends PayPalClient {
   
  public HttpResponse<Product> createProduct(boolean debug) throws IOException {
	  ProductCreateRequest request = new ProductCreateRequest();
	request.requestBody( new ProductRequest());
	  HttpResponse<Product> response = client().execute(request);
	  if(debug) {
		  System.out.println(response.result());
	  }
   
    return response;
  }

   
  /**
   *This driver function invokes the createOrder function to create
   *a sample order.
   */
  public static void main(String args[]) {
	// 同时支持代理 HTTP/HTTPS 请求
	  System.setProperty("proxyHost","127.0.0.1");
	  System.setProperty("proxyPort","1080");
    try {
    	new CreateProduct().createProduct(true);
    } catch (HttpException e) {
      System.out.println(e.getLocalizedMessage());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
